package com.scau.beyondboy.controller;
import com.scau.beyondboy.model.Aritcle;
import com.scau.beyondboy.service.AritcleService;
import org.apache.ibatis.annotations.Param;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
/**
 * Author:beyondboy
 * Gmail:xuguoli.scau@gmail.com
 * Date: 2016/2/18
 * Time: 14:18
 */
@Controller
@RequestMapping("/aritcle")
public class AritcleController
{
    private static Logger logger= Logger.getLogger(AritcleController.class);
    @Resource
    private AritcleService aritcleService;
    @RequestMapping("/show")
    public String showAll()
    {
        return "showArticle";
    }
    @RequestMapping("/getAllArticle")
    @ResponseBody
    public List<Aritcle> getAllArticle()
    {
        return aritcleService.getAll();
    }
    @RequestMapping("/add")
    public String addArticle(Aritcle aritcle)
    {
        System.out.println("aritcle.getPulishDate() = " + aritcle.getPulishDate());
        aritcleService.add(aritcle);
        return "redirect:/aritcle/show";
    }
    @RequestMapping(value = "/delete")
    public String deleteArticle(@RequestParam int articleId)
    {
        aritcleService.delete(articleId);
        return "redirect:/aritcle/show";
    }
    /**根据条件查询语句*/
    @RequestMapping("/queryCondition")
    @ResponseBody
    public List<Aritcle> queryCondition(@Param("field")String field, @Param("condition")String condition)
    {
        return aritcleService.queryByCdn(field,condition);
    }
    /**分页显示*/
    @RequestMapping("/page")
    @ResponseBody
    public List<Aritcle> page(@Param("start")int start,@Param("end")int end)
    {
        return aritcleService.getLimitFind(start,end);
    }
    /**获取数据数目*/
    @RequestMapping("/getCount")
    @ResponseBody
    public Integer getCount()
    {
        return aritcleService.getCount();
    }
}
